package com.cx.controller.lq;

import com.cx.constant.ConstantData;
import com.cx.pojo.Game;
import com.cx.pojo.GameInfo;
import com.cx.pojo.Gamelibrary;
import com.cx.pojo.User;
import com.cx.service.lq.GamelibraryService;
import com.cx.service.lq.GamelistService;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("gamelibrary")
public class GamelibraryController {
    @Autowired
    GamelibraryService gamelibraryService;

    //userId 获取
    //在gamelibrary中根据UserID查找GameID 根据gameID找出游戏
    @RequestMapping("gamelist")
    @ResponseBody
    @JsonFormat(shape=JsonFormat.Shape.STRING,pattern="yyyy-MM-dd",timezone="GMT+8")
    public List<GameInfo> selectAll(HttpSession session) {
        User user = (User) session.getAttribute(ConstantData.SESSION_KEY);
        int userId = user.getUserId();
        List<GameInfo> gameInfos = gamelibraryService.selectByUserId(userId);
        return gameInfos;
    }

    @RequestMapping("selectgame")
    @ResponseBody
    @JsonFormat(shape=JsonFormat.Shape.STRING,pattern="yyyy-MM-dd",timezone="GMT+8")
    public List<GameInfo> selectGame(HttpSession session,String name) {
        User user = (User) session.getAttribute(ConstantData.SESSION_KEY);
        int userId = user.getUserId();
        List<GameInfo> gameInfos = gamelibraryService.selectByName(userId,name);
        return gameInfos;
    }
}

